// Funnelback auto-completion jQuery plugin
// Author: Nicolas Guillaumin, Matt Sheppard
// Copyright Funnelback, 2012
// $Id: jquery.funnelback-completion.js 41163 2014-11-28 06:00:43Z msheppard $
(function($) {
$.fn.fbcompletion = function(settings) {
var facetBasedCompletionSuccess = function(config, request, data) {
var responses = new Array();
var partial_query_parts = request.term.split(" ");
var last_partial_term = partial_query_parts[partial_query_parts.length -1];
var partial_complete_query = request.term.substring(0,
request.term.length - last_partial_term.length);
if(last_partial_term.substring(0,1) == '|') {
last_partial_term = last_partial_term.substring(last_partial_term.indexOf(':') + 1, last_partial_term.length);
}
var lower_last_partial_term = last_partial_term.toLowerCase();
var facets = data.response.facets;
var rank = 1;
for (var i=0; i
e.g. if question is query=old&bar=foo and partialQuery is 'hello moth' *it will return query=hello&bar=foo
* * */ function replaceQueryInQuestionWithPartialQuery(encodedQuestion, partialQuery, profile) { var question = htmlDecode(encodedQuestion); var partial_query_parts = partialQuery.split(" "); var last_partial_term = partial_query_parts[partial_query_parts.length -1]; var partial_complete_query = partialQuery.substring(0, partialQuery.length - last_partial_term.length); if(partial_complete_query.length == 0) { partial_complete_query = '!padrenull'; } var questionsParts = question.split('&'); var newQuestion = ''; var changedQuery = false; var changedProfile = false; for(var i = 0; i < questionsParts.length; i++) { if(questionsParts[i].substring(0, 6) == 'query=') { newQuestion += 'query=' + partial_complete_query; changedQuery = true; } else if(profile != null && questionsParts[i].substring(0, 8) == 'profile=') { newQuestion += 'profile=' + profile; changedProfile = true; } else { newQuestion += questionsParts[i]; } newQuestion += '&'; } if(!changedQuery) { newQuestion += 'query=' + partial_complete_query; newQuestion += '&'; } if(!changedProfile && profile != null) { newQuestion += 'profile=' + profile; newQuestion += '&'; } return newQuestion.substring(0, newQuestion.length -1); } function htmlDecode(value){ return $('').html(value).text(); } })(jQuery);